<?php

/* 
 * 供应操作控制器
 * @author wyb
 */
namespace Shells\Controller;
class SupplyController extends BaseController{
    
    /**
     * 供应产品自动过期
     */
    public function supplyGoodsAutoInvalid() {
        $goods_supply_list = M('goods_supply')->where('`invalid_time` > '.time(). ' OR `stock_num` <= 0 AND `status` = 2')->select();
        if( $goods_supply_list ) {
            foreach( $goods_supply_list as $key => $value ) {
                $index_flag = false;
                //按照库存为0过期
                if( $value['is_invalid_type'] == 1 && $value['stock_num'] <= 0) {
                    $index_flag = true;
                } else if(  $value['is_invalid_type'] == 2 && $value['invalid_time'] < time() ) { //按照时间过期
                    $index_flag = true;
                }
                //判断是否已过期 如果是则修改数据
                if( $index_flag === true ) {
                    M('goods_supply')->where(array('id' => $value['id']))->save(array('status' => 3));
                }
            }
        }
    }
    
    /**
     * 供应产品到货
     */
    public function supplyGoodsAutoArrive() {
        //修改设定到货时间已到的数据
        M('goods_supply')->where('`stock_status` = 2 AND `stock_arrive_time` > '.time())->save(array('stock_status' => 1));
    }
    
}


